cmake_minimum_required(VERSION 3.10)
project(surf VERSION 2.1)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(PkgConfig REQUIRED)

pkg_check_modules(SURF_DEPS REQUIRED
    x11
    glib-2.0
    gdk-3.0
    atk
    gcr-3
    gtk+-3.0
    webkit2gtk-4.1
)

pkg_check_modules(WEBEXT_DEPS REQUIRED
    webkit2gtk-4.1
    webkit2gtk-web-extension-4.1
    gio-2.0
)

add_executable(surf surf.c)
target_compile_options(surf PRIVATE -fPIC ${SURF_DEPS_CFLAGS_OTHER})
target_compile_definitions(surf PRIVATE
    VERSION="${PROJECT_VERSION}"
    GCR_API_SUBJECT_TO_CHANGE
    LIBPREFIX="/usr/local/lib"
    WEBEXTDIR="/usr/local/lib/surf"
    _DEFAULT_SOURCE
)
target_include_directories(surf PRIVATE ${SURF_DEPS_INCLUDE_DIRS})
target_link_libraries(surf PRIVATE ${SURF_DEPS_LIBRARIES} gthread-2.0)

add_library(webext-surf SHARED webext-surf.c)
target_compile_options(webext-surf PRIVATE -fPIC ${WEBEXT_DEPS_CFLAGS_OTHER})
target_include_directories(webext-surf PRIVATE ${WEBEXT_DEPS_INCLUDE_DIRS})
target_link_libraries(webext-surf PRIVATE ${WEBEXT_DEPS_LIBRARIES})
set_target_properties(webext-surf PROPERTIES LINK_FLAGS "-Wl,-soname,webext-surf.so")